package com.wzcl.app.model.vo;

import com.wzcl.app.dao.model.Commodity;
import com.wzcl.app.dao.model.OrderDetail;
import com.wzcl.app.model.common.WZCL;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@EqualsAndHashCode(callSuper = false)
@Data
public class OrderDetailVo extends BaseVo {
    private static final long serialVersionUID = -2368659782025017850L;

    @ApiModelProperty(value = "原价")
    private String oldPrice;

    @ApiModelProperty(value = "现价")
    private String currentPrice;

    @ApiModelProperty(value = "实际支付")
    private String pay;

    @ApiModelProperty(value = "规格")
    private String spec;

    //------------商品相关-----------//
    @ApiModelProperty(value = "商品Id")
    private Integer commodityId;

    @ApiModelProperty(value = "商品资源Id")
    private Integer commodityResourceId;

    @ApiModelProperty(value = "类型")
    private Integer commodityType;
    private String commodityTypeStr;

    @ApiModelProperty(value = "商品名称")
    private String commodityName;

    @ApiModelProperty(value = "图片")
    private List<String> commodityPictures;

    private OrderDetailVo(){
    }

    public static OrderDetailVo create(OrderDetail orderDetail){
        OrderDetailVo orderDetailVo = new OrderDetailVo();
        BeanUtils.copyProperties(orderDetail,orderDetailVo,"pay");
        orderDetailVo.pay = orderDetail.getPay().setScale(2, BigDecimal.ROUND_DOWN).toString();
        Commodity commodity = orderDetail.getCommodity();
        if(commodity !=null){
            orderDetailVo.commodityId = commodity.getId();
            orderDetailVo.commodityResourceId = commodity.getId();
            orderDetailVo.commodityType = commodity.getId();
            orderDetailVo.commodityName = commodity.getName();
            if(StringUtils.isNotBlank(commodity.getPictures())){
                orderDetailVo.commodityPictures = Arrays.asList(commodity.getPictures().split(","));
            }else{
                ArrayList<String> list = new ArrayList<>();
                list.add(DEFAULT_IMAGE);
                orderDetailVo.commodityPictures = list;
            }
        }
        return orderDetailVo;
    }


    @Override
    public void translationValueStr() {
        Map<String, Map<Integer, String>> map = getTranslationMap();
        if(this.commodityType != null){
            this.commodityTypeStr=map.get(WZCL.GROUP_NAME.COMMODITY_TYPE).get(this.commodityType);
        }
    }

    @Override
    public void processResources() {

    }
}
